class Solution {
    public String multiply(String num1, String num2) {
        int n=num1.length(),m=num2.length();
        char[] n1=new StringBuffer(num1).reverse().toString().toCharArray();
        char[] n2=new StringBuffer(num2).reverse().toString().toCharArray();
        int[] tmp=new int [n+m-1];
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                tmp[i+j]+=(n1[i]-'0')*(n2[j]-'0');
            }
        }
        StringBuffer ret=new StringBuffer();
        int cur=0,t=0;
        while(cur<n+m-1){
            t+=tmp[cur++];
            ret.append((char)(t%10+'0'));
            t/=10;
        }
        while(t!=0){
            ret.append((char)(t%10+'0'));
            t/=10;
        }
        if(ret.length()>1&&ret.charAt(ret.length()-1)=='0'){
            return "0";            
        }
        return ret.reverse().toString();
    }
}